#ifndef IPACHAGE_H
#define IPACHAGE_H

#include <iostream>
#include <boost/shared_ptr.hpp>

using namespace std;

#pragma pack(push)
#pragma pack(1)
struct Header
{
	Header(int id = 0, int sz = 0) : id_(id), size_(sz){}
	int id_;
	int size_;
	int seq_;
};
#pragma pack(pop)

class IIoHandler;

class IPackage
{
public:
	typedef boost::shared_ptr<IPackage> Ptr;
	virtual ~IPackage(){}
	virtual Ptr clone() = 0;
	virtual void poll(istream& is) = 0;
	virtual void push(ostream& os) = 0;
	virtual size_t size() const = 0;
	virtual size_t messageID() const = 0;
	virtual void preSend(boost::shared_ptr<IIoHandler> ioHandler) {}
	virtual void handle(boost::shared_ptr<IIoHandler> ioHandler) = 0;

	static ostream& write(ostream& os, IPackage& packge);
	static ostream& write(ostream& os, IPackage& packge, unsigned int seq);
	static IPackage::Ptr read(istream& is);
	static IPackage::Ptr read(istream& is, const Header& header);
};


#endif
